<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债券代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqdm">
              <a-input v-model="model.zqdm" placeholder="请输入债券代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债券总托管机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqztgjg">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择债券总托管机构"
                v-model="model.zqztgjg"
                dict="llbb_param_config,name,code"
                pidValue="10269952371b4481ac7d0aa33b1abefc"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债券品种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqpz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择债券品种"
                v-model="model.zqpz"
                dict="llbb_param_config,name,code"
                pidValue="4c0750a76cdb41eda0b5c191fe616e67"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债券信用级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqxyjb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择债券信用级别"
                v-model="model.zqxyjb"
                dict="llbb_param_config,name,code"
                pidValue="3b78832bdfd8427a88decf02cc933dc8"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择币种"
                v-model="model.bz"
                dict="jrsj_bz_config,name,code"
                pidValue="1382973175608823809"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="债权债务登记日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqzwdjr">
              <j-date placeholder="请选择债权债务登记日" v-model="model.zqzwdjr"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="起息日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qxr">
              <j-date placeholder="请选择起息日" v-model="model.qxr"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="兑付日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dfrq">
              <j-date placeholder="请选择兑付日期" v-model="model.dfrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="票面利率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pmll">
              <a-input-number v-model="model.pmll" placeholder="请输入票面利率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人证件代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrzjdm">
              <a-input v-model="model.fxrzjdm" placeholder="请输入发行人证件代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人地区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrdqdm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发行人地区代码"
                v-model="model.fxrdqdm"
                dict="jrsj_xzqhdm_config,name,code"
                pidValue="1"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrhy">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发行人行业"
                v-model="model.fxrhy"
                dict="jrsj_hyfl_config2,name,code"
                pidValue="1"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人企业规模" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrqygm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发行人企业规模"
                v-model="model.fxrqygm"
                dict="llbb_param_config,name,code"
                pidValue="197a02d9852d4faa9c69fdc93d6a0943"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人经济成分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrjjcf">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发行人经济成分"
                v-model="model.fxrjjcf"
                dict="llbb_param_config2,name,code"
                pidValue="1382968826283347970"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发行人国民经济部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fxrgmjjbm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择发行人国民经济部门"
                v-model="model.fxrgmjjbm"
                dict="llbb_param_config,name,code"
                pidValue="1382949237084336130"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jyrq">
              <j-date placeholder="请选择交易日期" v-model="model.jyrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jylsh">
              <a-input v-model="model.jylsh" placeholder="请输入交易流水号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="成交金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cjje">
              <a-input-number v-model="model.cjje" placeholder="请输入成交金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="成交金额折人民币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cjjezrmb">
              <a-input-number v-model="model.cjjezrmb" placeholder="请输入成交金额折人民币" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="买入/卖出标志" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mrmcbz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择买入/卖出标志"
                v-model="model.mrmcbz"
                dict="llbb_param_config,name,code"
                pidValue="3a20323161d346a7b3f6f524284c2842"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdStoBonAmtInfForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsCdStoBonAmtInf/jsCdStoBonAmtInf/add",
          edit: "/jsCdStoBonAmtInf/jsCdStoBonAmtInf/edit",
          queryById: "/jsCdStoBonAmtInf/jsCdStoBonAmtInf/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
